﻿namespace Cik.Gapi4net.Testing
{
    using System;
    using Gapi4Net;
    using Gapi4Net.Domain.Output.BlogSearch;
    using Gapi4Net.Domain.Output.BookSearch;
    using Gapi4Net.Domain.Output.ImageSearch;
    using Gapi4Net.Domain.Output.LocalSearch;
    using Gapi4Net.Domain.Output.NewsSearch;
    using Gapi4Net.Domain.Output.PatentSearch;
    using Gapi4Net.Domain.Output.TranslateSearch.DetectLanguage;
    using Gapi4Net.Domain.Output.TranslateSearch.TranslateLanguage;
    using Gapi4Net.Domain.Output.VideoSearch;
    using Gapi4Net.Domain.Output.WebSearch;
    using Gapi4Net.Service.Contracts;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Moq;

    [TestClass]
    public class GApi4NetTesting
    {
        private GApi4Net _gapi4net;

        private Mock<IBlogSearchService> _blogSearchService;
        private Mock<IBookSearchService> _bookSearchService;
        private Mock<IImageSearchService> _imageSearchService;
        private Mock<ILocalSearchService> _localSearchService;
        private Mock<INewsSearchService> _newsSearchService;
        private Mock<IPatentSearchService> _patentSearchService;
        private Mock<ITranslateService> _translateService;
        private Mock<IVideoSearchService> _videoSearchService;
        private Mock<IWebSearchService> _webSearchService;

        [TestInitialize]
        public void Init_Testing()
        {
            _gapi4net = new GApi4Net();

            // mocking all service instances
            _blogSearchService = new Mock<IBlogSearchService>();
            _bookSearchService = new Mock<IBookSearchService>();
            _imageSearchService = new Mock<IImageSearchService>();
            _localSearchService = new Mock<ILocalSearchService>();
            _newsSearchService = new Mock<INewsSearchService>();
            _patentSearchService = new Mock<IPatentSearchService>();
            _translateService = new Mock<ITranslateService>();
            _videoSearchService = new Mock<IVideoSearchService>();
            _webSearchService = new Mock<IWebSearchService>();

            // set all services to GApi4Net instance
            _gapi4net.BlogService = _blogSearchService.Object;
            _gapi4net.BookService = _bookSearchService.Object;
            _gapi4net.ImageService = _imageSearchService.Object;
            _gapi4net.LocalService = _localSearchService.Object;
            _gapi4net.NewsService = _newsSearchService.Object;
            _gapi4net.PatentService = _patentSearchService.Object;
            _gapi4net.TranslateService = _translateService.Object;
            _gapi4net.VideoService = _videoSearchService.Object;
            _gapi4net.WebService = _webSearchService.Object;
        }

        [TestMethod]
        public void Can_Call_Blog_Search()
        {
            // Arrange
            var expectedObj = new BlogSearchResult { ResponseStatus = 400, ResponseData = null, ResponseDetails = "test" };

            _blogSearchService.Setup(x => x.Search(It.IsAny<string>(), It.IsAny<string>())).Returns(expectedObj);

            // Act
            var result = _gapi4net.BlogSearch();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedObj.ResponseStatus, 400);
            Assert.AreEqual(expectedObj.ResponseDetails, "test");
        }

        [TestMethod]
        public void Can_Call_Book_Search()
        {
            // Arrange
            var expectedObj = new BookSearchResult { ResponseStatus = 400, ResponseData = null, ResponseDetails = "test" };

            _bookSearchService.Setup(x => x.Search(It.IsAny<string>(), It.IsAny<string>())).Returns(expectedObj);

            // Act
            var result = _gapi4net.BookSearch();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedObj.ResponseStatus, 400);
            Assert.AreEqual(expectedObj.ResponseDetails, "test");
        }

        [TestMethod]
        public void Can_Call_Image_Search()
        {
            // Arrange
            var expectedObj = new ImageSearchResult { ResponseStatus = 400, ResponseData = null, ResponseDetails = "test" };

            _imageSearchService.Setup(x => x.Search(It.IsAny<string>(), It.IsAny<string>())).Returns(expectedObj);

            // Act
            var result = _gapi4net.ImageSearch();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedObj.ResponseStatus, 400);
            Assert.AreEqual(expectedObj.ResponseDetails, "test");
        }

        [TestMethod]
        public void Can_Call_Local_Search()
        {
            // Arrange
            var expectedObj = new LocalSearchResult { ResponseStatus = 400, ResponseData = null, ResponseDetails = "test" };

            _localSearchService.Setup(x => x.Search(It.IsAny<string>(), It.IsAny<string>())).Returns(expectedObj);

            // Act
            var result = _gapi4net.LocalSearch();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedObj.ResponseStatus, 400);
            Assert.AreEqual(expectedObj.ResponseDetails, "test");
        }

        [TestMethod]
        public void Can_Call_News_Search()
        {
            // Arrange
            var expectedObj = new NewsSearchResult { ResponseStatus = 400, ResponseData = null, ResponseDetails = "test" };

            _newsSearchService.Setup(x => x.Search(It.IsAny<string>(), It.IsAny<string>())).Returns(expectedObj);

            // Act
            var result = _gapi4net.NewsSearch();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedObj.ResponseStatus, 400);
            Assert.AreEqual(expectedObj.ResponseDetails, "test");
        }

        [TestMethod]
        public void Can_Call_Patent_Search()
        {
            // Arrange
            var expectedObj = new PatentSearchResult { ResponseStatus = 400, ResponseData = null, ResponseDetails = "test" };

            _patentSearchService.Setup(x => x.Search(It.IsAny<string>(), It.IsAny<string>())).Returns(expectedObj);

            // Act
            var result = _gapi4net.PatentSearch();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedObj.ResponseStatus, 400);
            Assert.AreEqual(expectedObj.ResponseDetails, "test");
        }

        [TestMethod]
        public void Can_Call_Detect_Search()
        {
            // Arrange
            var expectedObj = new DetectResult { ResponseStatus = 400, ResponseData = null, ResponseDetails = "test" };

            _translateService.Setup(x => x.DetectLanguage(It.IsAny<string>(), It.IsAny<string>())).Returns(expectedObj);

            // Act
            var result = _gapi4net.DetectSearch();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedObj.ResponseStatus, 400);
            Assert.AreEqual(expectedObj.ResponseDetails, "test");
        }

        [TestMethod]
        public void Can_Call_Translate_Search()
        {
            // Arrange
            var expectedObj = new TranslateResult { ResponseStatus = 400, ResponseData = null, ResponseDetails = "test" };

            _translateService.Setup(x => x.Translate(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(expectedObj);

            // Act
            var result = _gapi4net.TranslateSearch();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedObj.ResponseStatus, 400);
            Assert.AreEqual(expectedObj.ResponseDetails, "test");
        }

        [TestMethod]
        public void Can_Call_Video_Search()
        {
            // Arrange
            var expectedObj = new VideoSearchResult { ResponseStatus = 400, ResponseData = null, ResponseDetails = "test" };

            _videoSearchService.Setup(x => x.Search(It.IsAny<string>(), It.IsAny<string>())).Returns(expectedObj);

            // Act
            var result = _gapi4net.VideoSearch();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedObj.ResponseStatus, 400);
            Assert.AreEqual(expectedObj.ResponseDetails, "test");
        }

        [TestMethod]
        public void Can_Call_Web_Search()
        {
            // Arrange
            var expectedObj = new WebSearchResult { ResponseStatus = 400, ResponseData = null, ResponseDetails = "test" };

            _webSearchService.Setup(x => x.Search(It.IsAny<string>(), It.IsAny<string>())).Returns(expectedObj);

            // Act
            var result = _gapi4net.WebSearch();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedObj.ResponseStatus, 400);
            Assert.AreEqual(expectedObj.ResponseDetails, "test");
        }

        [TestCleanup]
        public void End_Testing()
        {
            if (_gapi4net != null)
                GC.SuppressFinalize(_gapi4net);
        }
    }
}